package io.jpress.module.article.flowable.delegate;

import com.jfinal.aop.Inject;
import io.jpress.commons.flowable.FlowConsts;
import io.jpress.module.article.model.Article;
import io.jpress.module.article.service.ArticleService;
import io.jpress.core.flowable.AutoLoadServiceTaskDelegate;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;

@AutoLoadServiceTaskDelegate(title = "正式发布文章",type = "article",order = 1)
public class PublishArticleDelegate implements JavaDelegate {


    @Inject
    private ArticleService articleService;


    @Override
    public void execute(DelegateExecution execution) {
        Object articleId = execution.getVariable(FlowConsts.VAR_CONTENT_ID);
        Article article = articleService.findById(articleId);

        if (article != null && !article.isNormal()){
            article.setStatus(Article.STATUS_NORMAL);
            articleService.update(article);
        }
    }
}
